When a connection is established between a client and a server, the two entities dedicate a portion of their resources to the connection. Typically, after a data transfer session is completed, the connection between the client and the server is terminated by the client or the server by sending an IP packet (e.g., FIN packet). However, sometimes the client and the server can maintain the connection by using keepalive messages or heartbeat messages. A keepalive message can be sent an entity at one end of a connection to check the operational status of another entity at the other end of the connection. When the receiving entity receives a keepalive message from a sending entity, the receiving entity immediately replies with an acknowledgment message, thereby informing the sending entity that it is alive or operational. If, however, the sending entity does not receive an acknowledgement message for a period of time, the sending entity can terminate the connection.
The keepalive messages from these always-on applications allow the applications to receive messages with less delay. However, this improvement in latency has associated costs. These costs include consumption of a significant amount of energy in mobile devices, additional signaling in the mobile network and bandwidth consumption. For example, to be able to send keepalive messages frequently, a mobile device needs to frequently transition its radio between a high powered state and an idle state or remain in a high powered state instead of the idle state for a longer period of time, resulting in fast draining of battery. These radio transitions also cause additional signaling in the networks as radio resource control (RRC) messages need to be exchanged between the mobile device and base station to establish a radio link. Furthermore, each keepalive message can be as large as 20-60 bytes in size, and a large number of such keepalive messages from multiple application can add up to consume a substantial chunk of the network bandwidth. Thus keepalive optimization is desired. However, keepalive optimization can occur only when keepalives can be accurately detected.